package com.clothes.http;

import com.lzy.okgo.request.base.Request;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

import okhttp3.Response;

/**
 * Created by llf on 2017/9/8.
 */

public abstract class JsonCallBack<T> extends BaseCallBack<T>{

    private Type type;

    public JsonCallBack() {}


    @Override
    public void onStart(Request<T, ? extends Request> request) {
        super.onStart(request);
//        request.headers("header", "")
//                .params("token", "");
    }

    @Override
    public T convertResponse(Response response) throws Throwable {

        if (type == null) {
            Type genType = getClass().getGenericSuperclass();
            type = ((ParameterizedType) genType).getActualTypeArguments()[0];
        }

        JsonConvert<T> convert = new JsonConvert<>(type);
        return convert.convertResponse(response);
    }
}
